<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            background-color: #709b90;
            font-family: Arial, Helvetica, sans-serif;
        }

        .portfolio {
            display: grid;
            /* 最小列宽设置为200px,自动填充网格 */
            grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
            /* 隐式水平网络轨道大小设置为1fr */
            grid-auto-rows: 1fr;
            grid-gap: 1em;
            /* 设置网络布局算法为紧凑算法 */
            grid-auto-flow: dense;
        }

        .portfolio > figure {
            margin: 0;
        }

        .portfolio img {
            max-width: 100%;
        }

        .portfolio figcaption {
            padding: .3em .8em;
            background-color: rgba(0, 0, 0, 0.5);
            color: #fff;
            text-align: right;
        }
        /* 将带有featured的图片放大,占用横竖2个grid */
        .portfolio .featured {
            grid-row: span 2;
            grid-column: span 2;
        }

        /* 将每个网格变为弹性盒子,将主轴方向改为竖直方向 */
        .portfolio > figure {
            display: flex;
            flex-direction: column;
            margin: 0;
        }

        /* 弹性拉伸,用图片填充弹性盒子可用空间 */
        .portfolio img {
            flex: 1;
            /* 图片填充盒子,并不拉伸. */
            object-fit: cover;
            max-width: 100%;
        }

    </style>
</head>
<body>
    <div class="portfolio">
        <figure class="featured">
            <img src="https://img0.baidu.com/it/u=2927087216,3709369106&fm=253&fmt=auto&app=138&f=JPEG?w=200&h=200" alt="">
            <figcaption>Cat1</figcaption>
        </figure>
        <figure >
            <img src="https://img2.baidu.com/it/u=2896925942,2321664626&fm=253&fmt=auto&app=138&f=JPEG?w=200&h=200" alt="">
            <figcaption>Cat2</figcaption>
        </figure>
        <figure class="featured">
            <img src="http://img.duoziwang.com/2017/09/1603365846878.jpg" alt="">
            <figcaption>Cat3</figcaption>
        </figure>
        <figure >
            <img src="https://img1.baidu.com/it/u=3822608906,3171490476&fm=253&fmt=auto&app=138&f=JPEG?w=200&h=200" alt="">
            <figcaption>Cat4</figcaption>
        </figure>
        <figure class="featured">
            <img src="http://img.duoziwang.com/2021/05/09022306905363.jpg" alt="">
            <figcaption>Cat5</figcaption>
        </figure>
        <figure class="featured">
            <img src="https://img1.baidu.com/it/u=590777202,379664882&fm=253&fmt=auto&app=138&f=JPEG?w=200&h=200" alt="">
            <figcaption>Cat6</figcaption>
        </figure>
        <figure >
            <img src="http://img.duoziwang.com/2018/22/09191254904245.jpg" alt="">
            <figcaption>Cat7</figcaption>
        </figure>
    </div>
</body>
</html>